#include "glExt.h"
#include "Color4.h"
#include "Point2.h"
#include "Point3.h"
#include "Vector3.h"
#include "Quaternion.h"
#include "GlPlatform.h"
#include "Transform.h"

namespace Core {
namespace glExt {
	void emitColor( const Color4& color ) {
		glColor4f( color.r, color.g, color.b, color.a );
	}

	template<>
	void emitVertex2( const Point2_t<float>& pt ) {
		glVertex2f( pt.x, pt.y );
	}

	template<>
	void emitVertex2( const Point2_t<double>& pt ) {
		glVertex2d( pt.x, pt.y );
	}

	template<>
	void emitVertex2( const Point2_t<int>& pt ) {
		glVertex2i( pt.x, pt.y );
	}

	template<>
	void emitVertex3( const Point3_t<float>& pt ) {
		glVertex3f( pt.x, pt.y, pt.z );
	}

	template<>
	void emitVertex3( const Point3_t<double>& pt ) {
		glVertex3d( pt.x, pt.y, pt.z );
	}

	template<>
	void emitVertex3( const Point3_t<int>& pt ) {
		glVertex3i( pt.x, pt.y, pt.z );
	}

	template<>
	void emitNormal( const Vector3_t<double>& vec ) {
		glNormal3d( vec.x, vec.y, vec.z );
	}

	template<>
	void emitNormal( const Vector3_t<float>& vec ) {
		glNormal3f( vec.x, vec.y, vec.z );
	}

	template<>
	void rotate( const Quaternion4_t<float>& quat ) {
		float mat[4][4];
		quat.toMatrix4( mat );
		glMultMatrixf( &mat[0][0] );
	}

	template<>
	void rotate( const Quaternion4_t<double>& quat ) {
		double mat[4][4];
		quat.toMatrix4( mat );
		glMultMatrixd( &mat[0][0] );
	}

	template<>
	void translate( const Vector3_t<double>& vec ) {
		glTranslated( vec.x, vec.y, vec.z );
	}

	template<>
	void translate( const Vector3_t<float>& vec ) {
		glTranslatef( vec.x, vec.y, vec.z );
	}

	template<>
	void scale( const Vector3_t<double>& vec ) {
		glScaled( vec.x, vec.y, vec.z );
	}

	template<>
	void scale( const Vector3_t<float>& vec ) {
		glScalef( vec.x, vec.y, vec.z );
	}

	template<>
	void transform( const Transform3_t<float>& trans ) {
		translate( trans.position.fromOrigin() );
		rotate( trans.orientation );
		scale( trans.scale );
	}

	template<>
	void transform( const Transform3_t<double>& trans ) {
		translate( trans.position.fromOrigin() );
		rotate( trans.orientation );
		scale( trans.scale );
	}
}
}